package com.badlogic.agdwikisamples;

import com.badlogic.agdwikisamples.utils.BenchmarkActivity;

public class LoopBenchmark extends BenchmarkActivity
{
	static final int REPEATS = 5000;
	static final int COUNT = 10000;
	
	@Override
	public void benchmark() 
	{
		int[] values = new int[COUNT];
		int sum = 0;
		
		tic( );
		sum = 0;
		for( int j = 0; j < REPEATS; j++ )
			for( int i = 0; i < values.length; i++ )
				sum += values[i];
		toc( "for(int i=0;i<values.length;i++)");
		
		tic( );
		sum = 0;
		
		for( int j = 0; j < REPEATS; j++ )
			for( int i = 0, len = values.length; i < len; i++ )
				sum += values[i];
		toc( "for(int i=0,len=values.length;i<len;i++)");
		
		tic( );
		sum = 0;
		for( int j = 0; j < REPEATS; j++ )
			for( int value: values )
				sum += value;
		toc( "for(int value:values)" );
		
		info( "done" );
	}
}
